package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author ghy
 * @version 1.0
 * @date 2022-10-18 11:21
 */
@Component
@Aspect
public class ExecutionEfficiencyAdvice {

    //定义切入点
    @Pointcut("execution(* com.itheima.service.impl.AccountServiceImpl.*(..))")
    public void testSpeed(){}

    //环绕通知
    //1.环绕通知必须有返回值。目前返回值为void
    //2.环绕通知必须指定调用目标方法。
    @Around("testSpeed()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();

        Object proceed = pjp.proceed();//调用目标方法

        long end = System.currentTimeMillis();

        System.out.println("总共执行了" + (end-start) + "ms");
        return proceed;

    }

}
